<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core">

    <a4j:outputPanel style="overflow: hidden;"
                     layout="block" 
                     id="#{teamDetailPanelID}" >
        <rich:panel style="overflow: hidden;" 
                    rendered="#{not empty team}" >

            <f:facet name="header" >
                <h:panelGroup style="overflow: hidden;">
                    <h:outputText value="#{bundle.teamDetailTitle}" />

                    <a4j:commandButton image="/resources/icons/application-exit-icon.png" 
                                       execute="@this" render="#{teamDetailPanelID}"
                                       value="" styleClass="detailPanelCloseButton" >
                        <f:setPropertyActionListener target="#{teamManagedBean.currentlyDetailedTeam}" value="#{null}" /> 
                    </a4j:commandButton>
                </h:panelGroup>
            </f:facet>

            <rich:panel header="#{bundle.teamDetailInfoTitle}" >
                <h:panelGrid columns="2" >
                    <h:outputLabel value="#{bundle.teamName}: "
                                   for="detailTeamName" />
                    <h:outputText id="detailTeamName"
                                  value="#{team.team.name}" />
                    <h:outputLabel value="#{bundle.managerName}: "
                                   for="detailManagerName" />
                    <h:outputText id="detailManagerName"
                                  value="#{team.team.managerName}" />
                </h:panelGrid>

                <rich:dataTable value="#{team.statistics}" var="statistics"
                                noDataLabel="#{bundle.noStatistics}">
                    <rich:column>
                        <f:facet name="header">#{bundle.teamWins}</f:facet>
                        <h:outputText value="#{statistics.wins}" />
                    </rich:column>
                    <rich:column>
                        <f:facet name="header">#{bundle.teamDraws}</f:facet>
                        <h:outputText value="#{statistics.drawns}" />
                    </rich:column>
                    <rich:column>
                        <f:facet name="header">#{bundle.teamLosts}</f:facet>
                        <h:outputText value="#{statistics.losts}" />
                    </rich:column>
                    <rich:column>
                        <f:facet name="header">#{bundle.teamScoredGoals}</f:facet>
                        <h:outputText value="#{statistics.goalsScored}" />
                    </rich:column>
                    <rich:column>
                        <f:facet name="header">#{bundle.teamConcededGoals}</f:facet>
                        <h:outputText value="#{statistics.goalsConceded}" />
                    </rich:column>
                </rich:dataTable>

            </rich:panel>

            <rich:panel style="overflow: hidden;" id="detailedTeamPlayersPanel"
                        header="#{bundle.teamDetailPlayersTitle}" >
                <rich:dataGrid value="#{team.team.players}" var="player"
                               id="detailedTeamPlayers" 
                               elements="12" columns="3" >

                    <rich:panel style="overflow: hidden;" >

                        <f:facet name="header" >

                            <h:panelGroup> 

                                <h:outputText value="#{bundle.teamDetailPlayerTitle}" />

                                <a4j:commandButton image="/resources/icons/Change-pencil-icon.png" 
                                                   render="@none" value=""
                                                   style="width: 14px; 
                                                   height: 14px; 
                                                   vertical-align: bottom;
                                                   margin-left: 0.1em;"
                                                   rendered="#{request.isUserInRole('Archiver')}" 
                                                   action="#{playerManagedBean.processActionAndRedirect('EDIT')}">
                                    <f:setPropertyActionListener target="#{playerManagedBean.currentlyManagedPlayer}" value="#{player}" />
                                    <f:setPropertyActionListener target="#{playerManagedBean.playersTeam}" value="#{player.team}" />
                                    <f:setPropertyActionListener target="#{playerManagedBean.actionInvocationLocation}" value="team" />
                                </a4j:commandButton>

                                <a4j:commandButton image="/resources/icons/Button-Remove-icon.png" 
                                                   execute="@this" 
                                                   rendered="#{request.isUserInRole('Archiver')}" 
                                                   oncomplete="#{rich:component('deletePlayerConfirmWindow')}.show();"
                                                   value="" 
                                                   style="width: 12px; 
                                                   height: 12px; 
                                                   vertical-align: middle;
                                                   margin-left: 0.1em;"> 
                                    <f:setPropertyActionListener target="#{playerManagedBean.currentState}" value="DELETE" />
                                    <f:setPropertyActionListener target="#{playerManagedBean.currentlyManagedPlayer}" value="#{player}" />
                                    <f:setPropertyActionListener target="#{playerManagedBean.playersTeam}" value="#{team.team}" />
                                    <f:setPropertyActionListener target="#{playerManagedBean.actionInvocationLocation}" value="team" />
                                </a4j:commandButton>

                            </h:panelGroup>
                        </f:facet>


                        <h:panelGrid columns="2" >
                            <h:graphicImage library="images" name="player.png" width="54" height="54"/>

                            <h:panelGroup >
                                <h:panelGrid columns="2">
                                    <h:outputLabel value="#{bundle.playerDetailName}:"
                                                   for="playerFullName" style="white-space: nowrap;"/>
                                    <h:outputText value="#{player.firstName} #{player.lastName}"
                                                  id="playerFullName" />

                                    <h:outputLabel value="#{bundle.team}:" 
                                                   for="playerTeamName" />
                                    <h:outputText value="#{player.team.name}"
                                                  id="playerTeamName" />

                                    <h:outputLabel value="#{bundle.shirtNumber}:" 
                                                   for="playerShirtNumber" style="white-space: nowrap;" />
                                    <h:outputText value="#{player.shirtNumber}" 
                                                  id="playerShirtNumber" />
                                </h:panelGrid>
                            </h:panelGroup>
                        </h:panelGrid>

                    </rich:panel>

                    <f:facet name="footer" >
                        <rich:dataScroller for="detailedTeamPlayers" />
                    </f:facet>

                </rich:dataGrid>
            </rich:panel>

        </rich:panel>
    </a4j:outputPanel>

    <a4j:jsFunction name="removePlayer" action="#{playerManagedBean.handleAction}"
                    render="detailedTeamPlayersPanel" execute="@this" 
                    oncomplete="#{rich:component('deletePlayerConfirmWindow')}.hide();" />

    <ui:include src="./../dialogs/confirmationDialogWindow.xhtml" >
        <ui:param name="confirmDialogWindowID" value="deletePlayerConfirmWindow" />
        <ui:param name="confirmationText" value="#{bundle.deleteModalForm}" />
        <ui:param name="acceptButtonText" value="#{bundle.deleteButton}" />
        <ui:param name="acceptEventFunction" value="removePlayer()" />
    </ui:include>

</ui:composition>
